package com.itcam.cocomate.exception;

import com.itcam.cocomate.common.ErrorCode;
import lombok.Getter;

/**
 * @author : Cammy.Wu
 * Description : 自定义异常类
 * <p>
 * 1.相当于java的异常类，支持更多字段
 * 2.自定义构造函数，更灵活/快捷的设置字段
 */

@Getter
public class BusinessException extends RuntimeException {
    /**
     * 异常码
     */
    private final int code;

    /**
     * 描述
     */
    private final String description;

    public BusinessException(String message, int code, String description) {
        super(message);
        this.code = code;
        this.description = description;
    }

    public BusinessException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.description = errorCode.getDescription();
    }

    public BusinessException(ErrorCode errorCode, String description) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.description = description;
    }
}
